package test;

import java.awt.Color;
import java.awt.Graphics;

import javax.swing.JFrame;
import javax.swing.JPanel;

public class Hypnoswirl extends JPanel{
	// how far around the circle the ball is, in radians
	private double angle = 0;

	// how big the circle is
	private double radius = 15;

	// the center of the canvas
	private double centerX = 200;
	private double centerY = 200;
	private double x;
	private double y;
	
	public Hypnoswirl()
	{
		
	}
	
	private void start() throws InterruptedException
	{
		while(true)
		{
			 x = Math.sin(angle) * radius;
		     y = Math.cos(angle) * radius;
		    // move the ball forward
		    angle = angle + 0.1;
		    // make the circle bigger
		    radius = radius + 0.1;
		    Thread.sleep(20);
		    repaint();
		    
		    if(angle >360)
		    {
		    	angle = 0;
		    }
		}
	}
	
	@Override
	public void paint(Graphics g) {
		// since the circle is naturally centered at (0,0)
	    // we must add centerX and centerY
		g.setColor(Color.LIGHT_GRAY);
		g.fillRect(0, 0, 400, 400);
		g.setColor(Color.BLUE);
	    g.fillOval((int)(x + centerX), (int)(y + centerY), 40, 40);
	}
	
	public static void main(String[] args)
	{
		
		Hypnoswirl bb = new Hypnoswirl();
		JFrame jf = new JFrame();
		jf.setSize(400, 400);
		jf.add(bb);
		jf.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		jf.setVisible(true);
		
		try {
			bb.start();
		} catch (InterruptedException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		
	}
}
